package com.rslai.base.tool.autotest.mock.model;

import org.apache.commons.lang.StringUtils;

public abstract class Expectation {
    private String source;
    private String target;
    private String api;
    private String key;
    private String body;

    public Expectation() {
    }

    public void setTarget(String target) {
        if (StringUtils.isBlank(target)) {
            throw new RuntimeException("设置期望：target为必填项");
        } else {
            this.target = target;
            return;
        }
    }

    public void setApi(String api) {
        if (StringUtils.isBlank(api)) {
            throw new RuntimeException("设置期望：service为必填项");
        } else {
            this.api = api;
            return;
        }
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getTarget() {
        return target;
    }

    public String getApi() {
        return StringUtils.lowerCase(StringUtils.trim(api));
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        if (StringUtils.isBlank(source)) {
            throw new RuntimeException("设置期望：source为必填项");
        } else {
            this.source = source;
            return;
        }
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String computeKey() {
        String tempKey = getApi();
        if (StringUtils.isNotBlank(key))
            tempKey = (new StringBuilder()).append(tempKey).append("_").append(key).toString();
        return tempKey;
    }

    public void setDefaultValue(String defaultValue) {
        setBody(defaultValue);
    }

    public String getKey() {
        return key;
    }
}

